<?php
	/**
	 * @ignore
	 */
	if( defined("apl_".__FILE__)) return;
	define("apl_".__FILE__,"apl_".__FILE__);
	
	require_once(APL_ROOT."/html/apl_html_tag.php");
	require_once(APL_ROOT."/helpers/apl_html_helper.php");
	/**
	 * HTML Select Object
	 *
	 * @package apl
	 * @subpackage html
	 */
	class AplHtmlSelection extends AplHtmlTag
	{
		private $SelectionValues;
		private $SelectionTexts;
	
		public 	$MultipleChoice;
		public 	$Size;
		public 	$SelectedIndex;
	
		function __construct ()
		{
			parent::__construct("SELECT");
			$this->SelectionTexts = array();
			$this->SelectionValues = array();
			$this->SelectedIndex = 0;
		}
		
		/**
		 *	appends Value / Text data to Selection
		 * 	@param String $_Value
		 *	@param String $_Text
		 */
		function addPair( $paramValue,$paramText )
		{
			array_push( $this->SelectionTexts,$paramText);
			array_push( $this->SelectionValues,$paramValue);
		}
		/**
		 * Clears the contents of the Object
		 */
		function clear()
		{
			unset($this->SelectionTexts);
			unset($this->SelectionValues);
			$this->SelectionTexts = array();
			$this->SelectionValues = array();
		}
	 	/**
	  	 * Removes the item from the collection whose value given as parameter
	  	 * @param Mixed $_Value
	     */
		function removeValue( $paramValue )
		{
			$key = array_search($paramValue,$this->SelectionValues);
			if( is_int($key ))
			{
				RemoveArray($this->SelectionValues,$paramValue );
				RemoveArray( $this->SelectionTexts,$this->SelectionTexts[$key]);
			}
		}
	 	/**
	  	 *	Outputs the HTML tag
	  	 */
		function buildTag()
		{
			$custom = "";
			if( Apl::nvl($this->MultipleChoice,false) )
				$custom=$custom." multiple ";
			if( is_int($this->Size) )
				$custom=$custom." size= ".$this->Size." ";
			
			$this->CustomLine = $custom . " ". $this->CustomLine;
			$Tag = parent::TagStart();  
			for ($i=0;$i<count($this->SelectionValues); $i++)
			{
				$selText = " ";
				if($this->SelectionValues[$i]==$this->SelectedIndex )
					$selText = " selected ";			
				$Tag = $Tag ."<option ".
							$selText.
							" text='".
							$this->SelectionTexts[$i].
							"' value='".
							AplHtmlHelper::getJSString($this->SelectionValues[$i]).
							"'>".
							$this->SelectionTexts[$i].
							"</option>".CRLF;
			}
			return $Tag.parent::TagEnd();
		}
	}